﻿using System;
using System.Collections.Generic;

namespace RxjhServer.DbClss
{
	public class ItmesIDClass
	{
		private long ItmeId;

		private long Id;

		private object AsyncLocksw = new object();

		public ItmesIDClass()
		{
			try
			{
				this.ItmeId = 0L;
				this.Id = 0L;
				this.ItmeId = long.Parse(DBA.GetDBValue_3("EXEC GetItemSerial2 1000").ToString());
				this.Id = this.ItmeId + 1000L;
			}
			catch (Exception ex)
			{
				Form1.WriteLine(100, "全局ID出错" + ex.Message);
				World.conn.Dispose();
				List<Players> list = new List<Players>();
				foreach (Players current in World.allConnectedChars.Values)
				{
					list.Add(current);
				}
				foreach (Players current2 in list)
				{
					try
					{
						if (current2.Client != null)
						{
							current2.OpClient(1);
							current2.Client.Dispose();
						}
					}
					catch (Exception ex2)
					{
						Form1.WriteLine(1, "保存人物的数据 错误" + ex2.Message);
					}
				}
				list.Clear();
			}
		}

		public long AcquireBuffer()
		{
			long result;
			using (new Lock(this.AsyncLocksw, "AcquireBuffer"))
			{
				if (this.ItmeId < this.Id)
				{
					long itmeId;
					this.ItmeId = (itmeId = this.ItmeId) + 1L;
					result = itmeId;
				}
				else
				{
					this.ItmeId = long.Parse(DBA.GetDBValue_3("EXEC GetItemSerial2 1000").ToString());
					this.Id = this.ItmeId + 1000L;
					long itmeId2;
					this.ItmeId = (itmeId2 = this.ItmeId) + 1L;
					result = itmeId2;
				}
			}
			return result;
		}
	}
}
